package io.adrainty.bolee.insurance.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.adrainty.bolee.framework.commons.basic.ResultDTO;
import io.adrainty.bolee.framework.commons.utils.ResultDTOUtil;
import io.adrainty.bolee.insurance.models.entity.InsuranceEntity;
import io.adrainty.bolee.insurance.service.IInsuranceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>InsuranceController</p>
 *
 * @author AdRainty
 * @version V1.0.0
 * @description 保险管理
 * @since 2025/8/12 11:20:28
 */

@Tag(name = "保险管理")
@RestController
@RequestMapping("/insurance")
public class InsuranceController {

    @Resource
    private IInsuranceService insuranceService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @Operation(summary = "获取保险分页")
    public ResultDTO<IPage<InsuranceEntity>> getInsurancePage(@PathVariable("pageNum") Integer pageNum,
                                             @PathVariable("pageSize") Integer pageSize,
                                             @RequestBody InsuranceEntity insuranceEntity) {
        IPage<InsuranceEntity> insuranceVOResult = insuranceService.getInsurancePage(pageNum, pageSize, insuranceEntity);
        return ResultDTOUtil.success(insuranceVOResult);
    }

    @PutMapping
    @Operation(summary = "创建保险")
    public ResultDTO<InsuranceEntity> createInsurance(@RequestBody InsuranceEntity insuranceEntity) {
        InsuranceEntity insuranceVOResult = insuranceService.createInsurance(insuranceEntity);
        return ResultDTOUtil.success(insuranceVOResult);
    }

    @PatchMapping
    @Operation(summary = "修改保险")
    public ResultDTO<Boolean> updateInsurance(@RequestBody InsuranceEntity insuranceEntity) {
        Boolean result = insuranceService.updateInsurance(insuranceEntity);
        return ResultDTOUtil.success(result);
    }

    @PostMapping("/insurance/{insuranceId}")
    @Operation(summary = "查询保险详情")
    public ResultDTO<InsuranceEntity> findInsuranceDetails(@PathVariable("insuranceId") Long insuranceId) {
        InsuranceEntity insuranceVOResult = insuranceService.findInsuranceDetails(insuranceId);
        return ResultDTOUtil.success(insuranceVOResult);
    }

}
